<!doctype html>
<html class="no-js">
<head>
    <meta charset="UTF-8">
    <title>修改新闻 | 校园知事</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="icon" type="image/x-icon" href="/favicon.ico">
    <link rel="stylesheet" href="/assets/css/amazeui.min.css" />
    <link rel="stylesheet" href="/assets/css/admin.css">
    <link rel="stylesheet" href="/assets/css/appadmin.css">
    <link rel="stylesheet" href="/assets/css/amazeui.datetimepicker.css" />
</head>
<body>
    {{template "admin/naver.html" .}}
    <!-- content start -->
    <!-- content start -->
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf">
                    <strong class="am-text-primary am-text-lg" style="color: #222222;">修改新闻</strong>
                </div>
            </div>
            <hr>
            <div class="am-tabs am-margin" data-am-tabs>
                <ul class="am-tabs-nav am-nav am-nav-tabs">
                    <li class="am-active"><a href="#tab1">填写信息</a></li>
                </ul>
                <div class="am-tabs-bd">
                    <div class="am-tab-panel am-fade am-in am-active" id="tab1">
                        <div class="am-g am-margin-top">
                            <div class="am-u-sm-4 am-u-md-2  am-text-center">所属大类</div>
                            <div class="am-u-sm-8 am-u-md-10">
                                <select id="BigDropList" onchange="changeSmall(this)" data-am-selected="{btnSize: 'sm'}">
                                    {{range $k,$v:=.BigList}}
                                    {{if $k}}
                                    <option value="{{$v.Id}}">{{$v.Name}}</option>
                                    {{else}}
                                    <option selected="selected" value="{{$v.Id}}">{{$v.Name}}</option>
                                    {{end}}
                                    {{end}}
                                </select>
                            </div>
                        </div>
                        <div class="am-g am-margin-top">
                            <div class="am-u-sm-4 am-u-md-2  am-text-center">所属小类</div>
                            <div class="am-u-sm-8 am-u-md-10">
                                <select id="SmallDropList" data-am-selected="{btnSize: 'sm'}">
                                    <option value="0">无</option>
                                </select>
                            </div>{{range $k,$v:= .SmallVal}}<input type="hidden" id="smallval{{$k}}" value="{{$v}}">{{end}}<input type="hidden" id="aid" value="{{.Id}}">
                        </div>
                        <form class="am-form">
                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2  am-text-center">
                                    文章标题
                                </div>
                                <div class="am-u-sm-8 am-u-md-5">
                                    <input type="text" id="title" maxlength="510" onblur="checkRepeat()" class="am-input-sm" value="{{.Detail.Title}}" />
                                </div>
                                <div class="am-hide-sm-only am-u-md-5" style="color:red;">*</div>
                            </div>
                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2  am-text-center">
                                    发布作者
                                </div>
                                <div class="am-u-sm-8 am-u-md-5 am-u-end col-end">
                                    <input type="text" id="author" maxlength="40" class="am-input-sm" value="{{.Detail.Author}}">
                                </div>
                                <div class="am-hide-sm-only am-u-md-5" style="color:red;">*</div>
                            </div>
                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2  am-text-center">
                                    信息来源
                                </div>
                                <div class="am-u-sm-8 am-u-md-5">
                                    <input type="text" id="origin" maxlength="40" class="am-input-sm" value="{{.Detail.Origin}}">
                                </div>
                                <div class="am-hide-sm-only am-u-md-5" style="color:red;">*</div>
                            </div>

                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2  am-text-center">
                                    发布日期
                                </div>
                                <div class="am-u-sm-8 am-u-md-5">
                                    <p>  <input type="text" id="date_now" value="{{ .Times}}" class="am-input-sm am-form-field" readonly> </p>
                                </div>
                                <div class="am-hide-sm-only am-u-md-5">*</div>
                            </div>

                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2  am-text-center">
                                    点击次数
                                </div>
                                <div class="am-u-sm-8 am-u-md-5">
                                    <input type="text" id="hits_count" value="{{.Detail.Hits }}" class="am-input-sm" maxlength="10" style="ime-mode:disabled" onkeyup="return ValidateNumber(this,value)" />
                                </div>
                                <div class="am-hide-sm-only am-u-md-5">*</div>
                            </div>
                           <!-- <div class="am-checkbox" style="margin:20px 0 10px 280px;font-size:16px;">
                                <label>
                                    <input type="checkbox" id="lunbotu" value="{{.Detail.Haspic}}" onchange="changecheckbox(this)"> 将本文第一张图片设为轮播图
                                </label>
                            </div>-->

                            <!--<small style="margin-left:280px;color:#D02B4E"></small><br>
                            <small style="margin-left:315px;color:#D02B4E"></small>-->

                            <div class="am-g am-margin-top-sm">
                                <div class="am-u-sm-12 am-u-md-2  am-text-center admin-form-text">
                                    内容描述
                                </div>
                                <div class="am-u-sm-12 am-u-md-10">
                                    <script id="editor" type="text/plain" style="height:500px;width:702px;">
                                    </script>
                                </div>
                            </div>

                        </form>

                    </div>
                </div>
            </div>
            <div class="am-margin">
                <button type="button"  class="am-btn am-btn-secondary am-btn-sm" onclick="savesubmit()">保存</button>
                <button type="button"  class="am-btn am-btn-secondary am-btn-sm" onclick="">不保存</button>
            </div>
        </div>
    </div>
   {{template "admin/footer.html" .}}

    <script type="text/javascript" charset="utf-8" src="/assets/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/assets/ueditor/ueditor.all.min.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="/assets/ueditor/lang/zh-cn.js"></script>
    <script type="text/javascript" charset="utf-8" src="/assets/laydate/laydate.js"></script>

    <script type="text/javascript">
        $(function(){
			var $bid=$("#BigDropList").val().trim();
			document.getElementById("SmallDropList").innerHTML=document.getElementById("smallval"+$bid).value
            $("#BigDropList>option[value=1]").removeAttr("selected")
            $("#BigDropList>option[value={{.Detail.Bigclassid}}]").attr("selected","selected")
            changeSmall(document.getElementById("BigDropList"));
            $("#SmallDropList>option[value={{.Detail.Smallclassid}}]").attr("selected","selected")
            {{if .Detail.Haspic}}
            $("#lunbotu").attr("checked","checked")
            {{end}}

            laydate({
                elem:'#date_now',
                format: 'YYYY-MM-DD hh:mm:ss', //日期格式
                istime: true, //是否开启时间选择
            }
                        );

        });

        var ue = UE.getEditor('editor');
        ue.addListener('ready', function () {
            ue.setContent('{{.Detail.Context}}');
        }
        );

        function changeSmall(obj){
				var $thissmall=document.getElementById("smallval"+obj.value)
				if($thissmall=== null){
					 document.getElementById("SmallDropList").innerHTML="<option value='0'>无</option>"
				}else{
					document.getElementById("SmallDropList").innerHTML=document.getElementById("smallval"+obj.value).value
				}
            }
        function checkRepeat(){
           	var $bid=$("#BigDropList").val().trim();
			var $sid=$("#SmallDropList").val().trim();
            var $title=$("#title");
            if ($title.val().trim()==='') {
                return ;
            }
            $.lintul('/admin/article/ct',{title:$title.val(),bid:$bid,sid:$sid},function(data){
                if (data.status===1) {
                    layer.msg('同类别新闻标题已存在', { offset: '15%'});
                     $title.focus();
                }
            });
        }
        function changecheckbox(obj){
            obj.value= obj.value==="1"?"0":"1"
        }
        function savesubmit(){
            var $bid=$("#BigDropList").val().trim();
            var $sid=$("#SmallDropList").val().trim();
            var $title=$("#title");
            if ($title.val().trim()===''){
                layer.msg('请输入新闻标题', { offset: '15%'});
                $title.focus();
                return ;
            }
            var $author=$("#author");
            if ($author.val().trim()===''){
                layer.msg('请输入新闻作者', { offset: '15%'});
                $author.focus();
                return ;
            }
            var $origin=$("#origin");
            if ($origin.val().trim()===''){
                layer.msg('请设置文章来源', { offset: '15%'});
                $origin.focus();
                return ;
            }
            var $context=UE.getEditor('editor').getContent()
            if ($context ===''){
                UE.getEditor('editor').focus();
                return
            }
            var $datenow=$("#date_now");
            if ($datenow.val().trim()===''){
                layer.msg('请设置时间', { offset: '15%'});
                $datenow.focus();
                return ;
            }
            $.lintul('/admin/article/editnew',{aid:$("#aid").val(),bid:$bid,sid:$sid,title:$title.val().trim(),author:$author.val().trim(),origin:$origin.val().trim(),context:$context,lunbotu:$("#lunbotu").val(),datenow:$datenow.val(),hitscount:$("#hits_count").val()},function(data){
                if (data.status === 1) {
                    layer.msg('发布新闻成功', { offset: '15%', icon: 6 ,time:1000}, function () {
                        window.location.href="/admin";
                    });
				}else if(data.status === 12){
					layer.msg('发布新闻失败,同类别新闻标题已存在', { offset: '15%', icon: 5 });
                } else {
                    layer.msg('发布新闻失败,请检查后重试', { offset: '15%', icon: 5 });
                }
            });
        }
        function ValidateNumber(e, pnumber){
            if (!/^\d+$/.test(pnumber)){
                e.value = /^\d+/.exec(e.value);}
            return false;
        }


    </script>
</body>
</html>
